package cn.qayy.controller;

import java.math.RoundingMode;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.qayy.constants.Constant;
import cn.qayy.dto.Msg;
import cn.qayy.dto.TcTable;
import cn.qayy.utils.DataSourceUtils;
/**
 * 流向提成
 * 
 * @author jobs1127
 *
 */
@Controller
@RequestMapping(value = "/tc")
@SuppressWarnings("all")
public class PlanTichenController {
	//年份
	static int year = 2018;
	//季度
	static int quarter=1;
	static String andSql = "";
	static String whereSql = "";
	//格式化数据 保留两位
	static DecimalFormat df = new DecimalFormat("0.00");
	static {
		df.setRoundingMode(RoundingMode.HALF_UP);
	}
	//晚交流向常量
	static float space_Rx = -0.0f;
	static float daqu_Rx = -0.00f;
	static float space_OTC = -0.0f;
	static float daqu_OTC = -0.00f;
	/***Rx 大区、片区、经理 18年任务线 表 记录了大区经理兼职片区经理的情况**/
	static List<TcTable> table = null;
	/***key=片区,value=上一年的存量任务线**/
	static Map<String,Double> taskmap = null;
	/***key=大区,value=上一年的存量任务线**/
	static Map<String,Double> daqu_taskmap = null;
	/**key=片区,value=当前实际完成量**/
	static Map<String,Double> summap = null;
	
	/**key=片区,value=当前实际完成量 用于计算新疆t1相关提成**/
	static Map<String,Double> xjsummap_t1 = null;
	
	/**key=大区,value= 当前实际完成量**/
	static Map<String,Double> daqu_summap = null;
	
	/***key=片区,value=当年新疆任务**/
	static Map<String,Double> xjtaskmap = null;
	/**key=片区,value=当前新疆实际完成量**/
	static Map<String,Double> xjsummap = null;
	/**key=片区,value=Q1新疆t1实际完成量**/
	static Map<String,Double> xjsummap_Q1T1 = null;
	/**key=片区,value=当前新疆T1实际完成量**/
	static Map<String,Double> xjT1summap = null;
	/**key=片区,value=当前新疆全省实际完成量**/
	static Map<String,Double> xjTotalsummap = null;
	/**key=片区,value=新疆基础阶段任务 还未初始化**/
	static Map<String,Double> xjBsummap = null;
	/**key=片区,value=新疆高阶阶段任务 还未初始化**/
	static Map<String,Double> xjGsummap = null;
	
	/**大区经理兼职片区经理  key=片区,value=是否为兼职片区**/
	static Map<String,Double> jianzhimap = null;
	
	/***
	 * 初始化数据 
	 * 0、按季度来计算提成
	 * 1、算提成之前，把2018年目标季度的所有来源和提成全部初始化为0
	 * 2、片区提成人、大区提成人、区域主管提成人、贡献提成人 【录入或系统赋值】
	 * year:指定的年
	 * quarter:指定的季度
	 * @throws SQLException 
	 */
	public void init(int y,int q) throws SQLException{
		table = new ArrayList<TcTable>(64);
		taskmap = new LinkedHashMap<String, Double>(64);
		daqu_taskmap = new LinkedHashMap<String, Double>(64);
		xjtaskmap = new LinkedHashMap<String, Double>(64);
		xjsummap_Q1T1 = new LinkedHashMap<String, Double>(64);
		summap = new LinkedHashMap<String, Double>(64);
		xjsummap_t1 = new LinkedHashMap<String, Double>(64);
		daqu_summap = new LinkedHashMap<String, Double>(64);
		xjsummap = new LinkedHashMap<String, Double>(64);
		xjT1summap = new LinkedHashMap<String, Double>(64);
		xjTotalsummap = new LinkedHashMap<String, Double>(64);
		xjBsummap = new LinkedHashMap<String, Double>(64);
		xjGsummap = new LinkedHashMap<String, Double>(64);
		jianzhimap = new LinkedHashMap<String, Double>(64);
		
		year=y;
		quarter=q;
		if(quarter == 1){
			andSql = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/03/31','%Y%m%d') ";
		}
		if(quarter == 2){
			andSql = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/04/01','%Y%m%d') AND DATE_FORMAT('"+year+"/06/30','%Y%m%d') ";
		}
		if(quarter == 3){
			andSql = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/07/01','%Y%m%d') AND DATE_FORMAT('"+year+"/09/30','%Y%m%d') ";
		}
		if(quarter == 4){
			andSql = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/10/01','%Y%m%d') AND DATE_FORMAT('"+year+"/12/31','%Y%m%d') ";
			whereSql = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/09/01','%Y%m%d') AND DATE_FORMAT('"+year+"/12/31','%Y%m%d') ";
		}
		
		//清零提成
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='押' "
				+ " where 1=1 "+andSql;
		query.update(sql,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
		
		//初始化 新疆喀什 协管
		//String zqb_sql2 = "update kdb_nss_log_plans set zgTcMan='' ";
		//query.update(zqb_sql2);
				
		//初始化 新疆喀什 协管
		//String zqb_sql = "update kdb_nss_log_plans set zgTcMan='詹奇兵' where space='新疆喀什' "+andSql;
		//query.update(zqb_sql);
		
		//初始化贡献提成人
		String gxtcmansql0 = "update kdb_nss_log_plans set gxTcMan='' where year='2018' ";
		String gxtcmansql1 = "update kdb_nss_log_plans set gxTcMan='拜合提亚尔' where year='2018' and terminal='墨玉县人民医院'";
		String gxtcmansql2 = "update kdb_nss_log_plans set gxTcMan='杨坤' where year='2018' and terminal in ('富蕴县妇幼保健院')";
		String gxtcmansql3 = "update kdb_nss_log_plans set gxTcMan='常莉' where year='2018' and terminal in ('新疆老年病医院','乌鲁木齐市中医医院','经济技术开发区(头屯河区)第一人民医院','乌鲁木齐金天川医院(有限责任公司)')";
		String gxtcmansql4 = "update kdb_nss_log_plans set gxTcMan='付旭心' where year='2018' and mouth >=4 and terminal in ('巴音郭楞蒙古自治州人民医院',"
				+ "'巴州红十字天山医院','博湖县人民医院','第二师库尔勒医院',"
				+ "'和静博爱皮肤病专科医院','和静县人民医院',"
				+ "'库尔勒市第一人民医院','库尔勒市团结医院','尉犁县人民医院','中国石油集团东方地球物理勘探有限责任公司塔里木物探处分公司')";
//		query.update(gxtcmansql0);
//		query.update(gxtcmansql1);
//		query.update(gxtcmansql2);
//		query.update(gxtcmansql3);
//		query.update(gxtcmansql4);
		
		//初始化 新疆当前年的标准任务;以及 大区经理兼职的片区
		//query_tc_table();
		
		//非新疆的各个【片区】、【大区】的存量线，根据当前流向表里的片区分组查询
		query_cl_task();
		
		//当前年新疆各片区的实际完成量
		//query_xj_task();
		//查询当前年新疆 全年实际完成量 Rx 纯销 
		//query_xj_total_task();
		
		
		/***
		 * 计算Q2提成时，summap先累加Q1的折量，然后在累加Q2的
		 */
		if(quarter == 2) {
			String andSqlQ1 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/03/31','%Y%m%d') ";
			//非新疆 查询各个片区，Q1的实际完成量
			String sqlQ1 = " select space space,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1
					+ " group by space";
			
			List<TcTable> list = query.query(sqlQ1, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list) {
				summap.put(tcTable.getSpace(),tcTable.getTask_18());
				System.out.println(tcTable.getSpace()+"--"+summap.get(tcTable.getSpace()));
			}
			
			//非新疆 查询各个大区，Q1的实际完成量
			String sqlQ1_daqu = " select daqu daqu,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1
					+ " group by daqu";
			
			List<TcTable> list_daqu = query.query(sqlQ1_daqu, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list_daqu) {
				daqu_summap.put(tcTable.getDaqu(),tcTable.getTask_18());
				System.out.println("q1大区:"+tcTable.getDaqu()+"--"+daqu_summap.get(tcTable.getDaqu()));
			}
		}
		/***
		 * 计算Q3提成时，summap先累加Q1的折量，累加Q2的,在累加Q3的
		 */
		if(quarter == 3) {
			String andSqlQ1Q2 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/06/30','%Y%m%d') ";
			//查询各个片区，Q1 Q2的实际完成量
			String sqlQ1Q2 = " select space space,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1Q2
					+ " group by space";
			List<TcTable> list = query.query(sqlQ1Q2, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list) {
				summap.put(tcTable.getSpace(),tcTable.getTask_18());
				System.out.println("q3片区:"+tcTable.getSpace()+"--"+summap.get(tcTable.getSpace()));
			}
			
			//非新疆 查询各个大区，Q1 Q2的实际完成量
			String sqlQ1Q2_daqu = " select daqu daqu,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1Q2
					+ " group by daqu";
			
			List<TcTable> list_daqu = query.query(sqlQ1Q2_daqu, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list_daqu) {
				daqu_summap.put(tcTable.getDaqu(),tcTable.getTask_18());
				System.out.println("q3大区:"+tcTable.getDaqu()+"--"+daqu_summap.get(tcTable.getDaqu()));
			}
		}
		/***
		 * 计算Q4提成时，summap先累加Q1~Q3的，再累加Q4的
		 */
		if(quarter == 4) {
			//Q1~Q3
			String andSqlQ1Q2Q3 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/09/30','%Y%m%d') ";
			
			//查询各个片区，Q1 Q2 Q3的实际完成量
			String sqlQ1Q2Q3 = " select space space,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1Q2Q3
					+ " group by space";
			List<TcTable> list = query.query(sqlQ1Q2Q3, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list) {
				summap.put(tcTable.getSpace(),tcTable.getTask_18());
				
				//xjsummap_t1.put(tcTable.getSpace(),tcTable.getTask_18());
				System.out.println("q4片区:"+tcTable.getSpace()+"--"+summap.get(tcTable.getSpace()));
			}
			
			// 查询各个大区，Q1~Q3的实际完成量
			String sqlQ1Q2Q3_daqu = " select daqu daqu,sum(xsScount) task_18 "
					+ " from kdb_nss_log_plans "
					+ " where judge ='纯销' "
					+ " and (xieyizhuangtai='Rx') "+andSqlQ1Q2Q3
					+ " group by daqu";
			
			List<TcTable> list_daqu = query.query(sqlQ1Q2Q3_daqu, new BeanListHandler<TcTable>(TcTable.class));
			for (TcTable tcTable : list_daqu) {
				daqu_summap.put(tcTable.getDaqu(),tcTable.getTask_18());
				System.out.println("q4大区:"+tcTable.getDaqu()+"--"+daqu_summap.get(tcTable.getDaqu()));
			}
		}
	}
	
	/**
	 * 初始化 新疆各个片区标准任务; 大区经理兼职的片区的初始化
	 * 查询提成相关的政策表
	 * @throws SQLException 
	 * tc_table 表里的单位是万
	 */
	public static void query_tc_table() throws SQLException {
		table.clear();
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select `daqu` daqu,`space` space,`mgr` mgr,`jianzhi` jianzhi,`task_18` task_18,gjtask_18 gjtask_18 from tc_table ";
		table.addAll(query.query(sql, new BeanListHandler<TcTable>(TcTable.class)));
		for (TcTable tcTable : table) {
			if(tcTable.getSpace().contains("新疆")) {
				//基础任务
				xjBsummap.put(tcTable.getSpace(),tcTable.getTask_18()*10000);
				//高阶任务
				xjGsummap.put(tcTable.getSpace(),tcTable.getGjtask_18()*10000);
			}
			jianzhimap.put(tcTable.getSpace(),tcTable.getJianzhi());
		}
		/***
		 * 大区经理离职，出现的特殊情况的处理
		 */
		if(quarter == 1) {
			jianzhimap.put("北京1区", 0.0);
		}
	}
	
	/***
	 * 查询2017年各个片区的存量任务线 Rx 纯销  
	 * 用于计算非新疆的Rx提成来源
	 * @throws SQLException 
	 */
	public static void query_cl_task() throws SQLException {
		//初始【片区】存量线
		table.clear();
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+(year-1)+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' GROUP BY SPACE";
		table.addAll(query.query(sql, new BeanListHandler<TcTable>(TcTable.class)));
		for (TcTable tcTable : table) {
			taskmap.put(tcTable.getSpace(),tcTable.getTask_18());
			System.out.println("片区存量线【"+tcTable.getSpace()+"】："+taskmap.get(tcTable.getSpace()));
		}
		
		//初始【大区】存量线
		table.clear();
		QueryRunner query2 = new QueryRunner(DataSourceUtils.getDataSource());
		String sql2 = "SELECT daqu daqu,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+(year-1)+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' GROUP BY daqu";
		table.addAll(query2.query(sql2, new BeanListHandler<TcTable>(TcTable.class)));
		for (TcTable tcTable : table) {
			daqu_taskmap.put(tcTable.getDaqu(),tcTable.getTask_18());
			System.out.println("大区存量线【"+tcTable.getDaqu()+"】："+daqu_taskmap.get(tcTable.getDaqu()));
		}
	}
	/***
	 * 查询当前年【新疆】 各个片区的实际完成量 Rx 纯销 
	 * @throws SQLException 
	 */
	public void query_xj_task() throws SQLException {
		table.clear();
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		/***
		 * Q1实际完成量计算方式
		 */
		if(quarter == 1) {
			/**
			 * 各片区新疆本年非T1的Q1的任务量
			 */
			String sql = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype not like '%T1%' "+andSql+" GROUP BY SPACE";
			table.addAll(query.query(sql, new BeanListHandler<TcTable>(TcTable.class)));
			for (TcTable tcTable : table) {
				xjsummap.put(tcTable.getSpace(),tcTable.getTask_18());
			}
			/**片区：新疆巴州，计算任务特殊，需要把T1的也加上，即：新疆巴州所有的***/
			String sql2 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and space like '%新疆巴州%' "+andSql+" GROUP BY SPACE";
			TcTable t2 =  query.query(sql2, new BeanHandler<TcTable>(TcTable.class));
			System.out.println("新疆巴州:"+t2.getTask_18());
			xjsummap.put(t2.getSpace(),t2.getTask_18());
			
			
			/***
			 * 新疆本年T1的Q1的完成任务量
			 */
			String q1t1 = "SELECT CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx'  AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype = 'T1' and space not like '%新疆巴州%' "+andSql;
			//Double q1t1sjtask = ((Long)query.query(q1t1, new ScalarHandler())).doubleValue();
			TcTable t = query.query(q1t1, new BeanHandler<TcTable>(TcTable.class));
			xjT1summap.put("t1", t.getTask_18());
			System.out.println("T1的Q1的完成量:"+ t.getTask_18());
		}
		if(quarter == 2) {
			/**
			 * 各片区新疆本年非T1的Q2的任务量
			 */
			//1、先计算一般片区的非T1的实际完成量
			//1.1 Q2的任务需要累加Q1的实际完成量
			String andSqlQ1 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/03/31','%Y%m%d') ";
			String sqlQ1 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype not like '%T1%' "+andSqlQ1+" GROUP BY SPACE";
			table.clear();
			table.addAll(query.query(sqlQ1, new BeanListHandler<TcTable>(TcTable.class)));
			for (TcTable tcTable : table) {
				xjsummap.put(tcTable.getSpace(),tcTable.getTask_18());
			}
			//1.2 Q2的任务需要累加Q1的实际完成量
			String sqlQ2 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype not like '%T1%' "+andSql+" GROUP BY SPACE";
			table.clear();
			table.addAll(query.query(sqlQ2, new BeanListHandler<TcTable>(TcTable.class)));
			for (TcTable tcTable : table) {
				String space = tcTable.getSpace();
				if(xjsummap.containsKey(space)) {
					double d1 = xjsummap.get(space);
					double d2 = tcTable.getTask_18();
					double d = d1+d2;
					xjsummap.put(space,d);
					System.out.println(tcTable.getSpace()+",Q2的累加完成量："+xjsummap.get(tcTable.getSpace()));
				} else {
					xjsummap.put(tcTable.getSpace(),tcTable.getTask_18());
				}
			}
			//计算特殊的情况，新疆巴州，新疆T1
			//1、新疆巴州Q1实际完成量
			String sqlBZQ1 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and space like '%新疆巴州%' and terminaltype like '%T3%' "+andSqlQ1+" GROUP BY SPACE";
			TcTable tBZQ1 =  query.query(sqlBZQ1, new BeanHandler<TcTable>(TcTable.class));
			xjsummap.put(tBZQ1.getSpace(),tBZQ1.getTask_18());
			//2、新疆巴州Q2实际完成量
			String sql2 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and space like '%新疆巴州%' and (terminaltype like '%T3%' or terminal in('273H','31分部卫生处','四师高炮','乌市军区边十团')) "+andSql+" GROUP BY SPACE";
			TcTable t2 =  query.query(sql2, new BeanHandler<TcTable>(TcTable.class));
			if(xjsummap.containsKey(t2.getSpace())) {
				xjsummap.put(t2.getSpace(),xjsummap.get(t2.getSpace())+t2.getTask_18());
				System.out.println("Q2新疆巴州累加完成量："+xjsummap.get(t2.getSpace()));
			} else {
				xjsummap.put(t2.getSpace(),t2.getTask_18());
			}
			
			
			/***
			 * 新疆本年T1的Q2的完成任务量
			 */
			//1、计算Q1的T1的实际完成量
			String q1t1 = "SELECT CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx'  AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype = 'T1' and space not like '%新疆巴州%' "+andSqlQ1;
			TcTable t = query.query(q1t1, new BeanHandler<TcTable>(TcTable.class));
			xjT1summap.put("t1", t.getTask_18());
			//2、计算Q2的T1的实际完成量
			String q2t1 = "SELECT CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx'  AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype = 'T1' and terminal not in('273H','31分部卫生处','四师高炮','乌市军区边十团') "+andSql;
			TcTable tct2 = query.query(q1t1, new BeanHandler<TcTable>(TcTable.class));
			if(xjT1summap.containsKey("t1")) {
				xjT1summap.put("t1", xjT1summap.get("t1")+tct2.getTask_18());
			} else {
				xjT1summap.put("t1", tct2.getTask_18());
			}
			System.out.println("T1的Q2的完成量:"+ xjT1summap.get("t1"));
		}
		
		if(quarter == 3) {
			//1、计算新疆各片区Q1~Q3的实际完成量
			String andSqlQ1_Q3 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/09/30','%Y%m%d') ";
			String sqlQ1_Q3 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 "+andSqlQ1_Q3+" GROUP BY SPACE";
			table.clear();
			table.addAll(query.query(sqlQ1_Q3, new BeanListHandler<TcTable>(TcTable.class)));
			for (TcTable tcTable : table) {
				xjsummap.put(tcTable.getSpace(),tcTable.getTask_18());
			}
		}
		if(quarter == 4) {
			//1、计算新疆各片区Q1~Q4的实际完成量
			String andSqlQ1_Q4 = " and DATE_FORMAT(sdate,'%Y%m%d') BETWEEN DATE_FORMAT('"+year+"/01/01','%Y%m%d') AND DATE_FORMAT('"+year+"/12/31','%Y%m%d') ";
			String sqlQ1_Q4 = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 "+andSqlQ1_Q4+" GROUP BY SPACE";
			table.clear();
			table.addAll(query.query(sqlQ1_Q4, new BeanListHandler<TcTable>(TcTable.class)));
			for (TcTable tcTable : table) {
				xjsummap.put(tcTable.getSpace(),tcTable.getTask_18());
			}
		}
	}
	/***
	 * 查询当前年新疆T1的实际完成量 Rx 纯销 
	 * @throws SQLException 
	 */
//	public void query_xj_T1_task() throws SQLException {
//		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
//		String sql = "SELECT CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 and terminaltype='T1'";
//		TcTable t = query.query(sql, new BeanHandler<TcTable>(TcTable.class));
//		xjT1summap.put("T1",t.getTask_18());
//	}
	/***
	 * 查询当前年新疆 全年实际完成量 Rx 纯销 
	 * @throws SQLException 
	 */
	public void query_xj_total_task() throws SQLException {
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "SELECT CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 ";
		TcTable t = query.query(sql, new BeanHandler<TcTable>(TcTable.class));
		xjTotalsummap.put("xjtotal",t.getTask_18());
	}
	
	/***
	 * 计算OTC提成
	 * @throws SQLException 
	 */
	public void OTC_TC() throws SQLException {
		String id = "";
		String counts = "0";
		float count =0f;
		String qudao="";
		String tx="";
		String mode="";
		String judge="";
		String space="";
		String wjlx="";
		String tcman="";
		String dqman="";//大区提成人
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,count count,terminaltype qudao, "
				+ " xieyizhuangtai tx,mode mode,judge judge,space space,money6 wjlx,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where judge in('纯销')"
				+ " and (xieyizhuangtai = 'OTC' "
				+ " ) "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			counts = list.get(i)[1]==null?"0":list.get(i)[1].toString();//数量
			qudao = list.get(i)[2]==null?"":list.get(i)[2].toString();//渠道
			tx = list.get(i)[3]==null?"":list.get(i)[3].toString();//条线
			mode = list.get(i)[4]==null?"":list.get(i)[4].toString();//模式
			judge = list.get(i)[5]==null?"":list.get(i)[5].toString();//行为
			space = list.get(i)[6]==null?"":list.get(i)[6].toString();//片区
			wjlx = list.get(i)[7]==null?"":list.get(i)[7].toString();//晚交流向
			tcman = list.get(i)[8]==null?"":list.get(i)[8].toString();//片区提成人
			dqman = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区提成人
			
			//存量
			float daqu_cl = 0;
			float space_cl = 0;
			//晚交
			float daqu_wj = 0;
			float space_wj = 0;
			try {
				count = Float.parseFloat(counts);
			} catch (NumberFormatException e1) {
				count=0;
			}
			//模式判断
			if(mode.contains("预付")) {
				if(judge.contains("纯销")) {
					daqu_cl = 0.0f;
					space_cl = 0.0f;
				} else if(judge.contains("销售")) {
					daqu_cl = 0.0f;
					space_cl = 0.0f;
				}
			} else if("小包".equals(mode) || "虚拟小包".equals(mode) || "自营".equals(mode)) {
				if(judge.contains("纯销")) {
					daqu_cl = 0.1f;
					space_cl = 0.5f;
				} else if(judge.contains("销售")) {
					daqu_cl = 0.0f;
					space_cl = 0.0f;
				}
			}
			
			//晚交流向判断
			if(wjlx.contains("晚交流向")) {
				daqu_wj = daqu_OTC;
				space_wj = space_OTC;
			}
			//大区经理兼职片区经理时，大区提成来源为0
			if(tcman != null && dqman != null && tcman.trim().equals(dqman.trim())) {
				daqu_cl = 0.0f;
			}
			
			String daqu_cl_tc = df.format(daqu_cl*count);
			String space_cl_tc =  df.format(space_cl*count);
			String daqu_wj_tc =  df.format(daqu_wj*count);
			String space_wj_tc =  df.format(space_wj*count);
			//初始化参数
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,0,0,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,0,0,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	
	/***
	 * 计算OTC提成
	 * @throws SQLException 
	 */
	public void OTC_TC_Q4() throws SQLException {
		String id = "";
		String counts = "0";
		float count =0f;
		String qudao="";
		String tx="";
		String mode="";
		String judge="";
		String space="";
		String wjlx="";
		String tcman="";
		String dqman="";//大区提成人
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,count count,terminaltype qudao, "
				+ " xieyizhuangtai tx,mode mode,judge judge,space space,money6 wjlx,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where judge in('纯销')"
				+ " and (xieyizhuangtai = 'OTC' "
				+ " ) "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			counts = list.get(i)[1]==null?"0":list.get(i)[1].toString();//数量
			qudao = list.get(i)[2]==null?"":list.get(i)[2].toString();//渠道
			tx = list.get(i)[3]==null?"":list.get(i)[3].toString();//条线
			mode = list.get(i)[4]==null?"":list.get(i)[4].toString();//模式
			judge = list.get(i)[5]==null?"":list.get(i)[5].toString();//行为
			space = list.get(i)[6]==null?"":list.get(i)[6].toString();//片区
			wjlx = list.get(i)[7]==null?"":list.get(i)[7].toString();//晚交流向
			tcman = list.get(i)[8]==null?"":list.get(i)[8].toString();//片区提成人
			dqman = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区提成人
			
			//存量
			float daqu_cl = 0;
			float space_cl = 0;
			//晚交
			float daqu_wj = 0;
			float space_wj = 0;
			try {
				count = Float.parseFloat(counts);
			} catch (NumberFormatException e1) {
				count=0;
			}
			//模式判断
			if(mode.contains("预付")) {
//				if(judge.contains("纯销")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				} else if(judge.contains("销售")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				}
				daqu_cl = 0.0f;
				space_cl = 0.0f;
			} else {
				if(judge.contains("纯销")) {
					daqu_cl = 0.1f;
					space_cl = 0.5f;
				} 
			}
			
			//晚交流向判断
			if(wjlx.contains("晚交流向")) {
				daqu_wj = -0.05f;
				space_wj = 0;
			}
			//大区经理兼职片区经理时，大区提成来源为0
			if(tcman != null && dqman != null && tcman.trim().equals(dqman.trim())) {
				daqu_cl = 0.0f;
			}
			
			String daqu_cl_tc = df.format(daqu_cl*count);
			String space_cl_tc =  df.format(space_cl*count);
			String daqu_wj_tc =  df.format(daqu_wj*count);
			String space_wj_tc =  df.format(space_wj*count);
			//初始化参数
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,0,0,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,0,0,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q4' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算OTC提成
	 * @throws SQLException 
	 */
	public void OTC_TC_Q3() throws SQLException {
		String id = "";
		String counts = "0";
		float count =0f;
		String qudao="";
		String tx="";
		String mode="";
		String judge="";
		String space="";
		String wjlx="";
		String tcman="";
		String dqman="";//大区提成人
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,count count,terminaltype qudao, "
				+ " xieyizhuangtai tx,mode mode,judge judge,space space,money6 wjlx,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where judge in('纯销')"
				+ " and (xieyizhuangtai = 'OTC' "
				+ " ) "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			counts = list.get(i)[1]==null?"0":list.get(i)[1].toString();//数量
			qudao = list.get(i)[2]==null?"":list.get(i)[2].toString();//渠道
			tx = list.get(i)[3]==null?"":list.get(i)[3].toString();//条线
			mode = list.get(i)[4]==null?"":list.get(i)[4].toString();//模式
			judge = list.get(i)[5]==null?"":list.get(i)[5].toString();//行为
			space = list.get(i)[6]==null?"":list.get(i)[6].toString();//片区
			wjlx = list.get(i)[7]==null?"":list.get(i)[7].toString();//晚交流向
			tcman = list.get(i)[8]==null?"":list.get(i)[8].toString();//片区提成人
			dqman = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区提成人
			
			//存量
			float daqu_cl = 0;
			float space_cl = 0;
			//晚交
			float daqu_wj = 0;
			float space_wj = 0;
			try {
				count = Float.parseFloat(counts);
			} catch (NumberFormatException e1) {
				count=0;
			}
			//模式判断
			if(mode.contains("预付")) {
//				if(judge.contains("纯销")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				} else if(judge.contains("销售")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				}
				daqu_cl = 0.0f;
				space_cl = 0.0f;
			} else {
				if(judge.contains("纯销")) {
					daqu_cl = 0.1f;
					space_cl = 0.5f;
				} 
			}
			
			//晚交流向判断
			if(wjlx.contains("晚交流向")) {
				daqu_wj = -0.05f;
				space_wj = 0;
			}
			//大区经理兼职片区经理时，大区提成来源为0
			if(tcman != null && dqman != null && tcman.trim().equals(dqman.trim())) {
				daqu_cl = 0.0f;
			}
			
			String daqu_cl_tc = df.format(daqu_cl*count);
			String space_cl_tc =  df.format(space_cl*count);
			String daqu_wj_tc =  df.format(daqu_wj*count);
			String space_wj_tc =  df.format(space_wj*count);
			//初始化参数
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,0,0,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,0,0,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q3' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算OTC提成 备份Q2
	 * @throws SQLException 
	 */
	public void OTC_TC_Q2() throws SQLException {
		String id = "";
		String counts = "0";
		float count =0f;
		String qudao="";
		String tx="";
		String mode="";
		String judge="";
		//String space="";
		String wjlx="";
		String tcman="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,count count,terminaltype qudao, "
				+ " xieyizhuangtai tx,mode mode,judge judge,space space,money6 wjlx,tichengbelong tcman "
				+ " from kdb_nss_log_plans "
				+ " where judge in('纯销')"
				+ " and (xieyizhuangtai = 'OTC' "
				+ " or (xieyizhuangtai='Rx' and terminaltype='T4')) "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			counts = list.get(i)[1]==null?"0":list.get(i)[1].toString();//数量
			qudao = list.get(i)[2]==null?"":list.get(i)[2].toString();//渠道
			tx = list.get(i)[3]==null?"":list.get(i)[3].toString();//条线
			mode = list.get(i)[4]==null?"":list.get(i)[4].toString();//模式
			judge = list.get(i)[5]==null?"":list.get(i)[5].toString();//行为
			//space = list.get(i)[6]==null?"":list.get(i)[6].toString();//片区
			wjlx = list.get(i)[7]==null?"":list.get(i)[7].toString();//晚交流向
			tcman = list.get(i)[8]==null?"":list.get(i)[8].toString();//片区提成人
			//存量
			float daqu_cl = 0;
			float space_cl = 0;
			//晚交
			float daqu_wj = 0;
			float space_wj = 0;
			try {
				count = Float.parseFloat(counts);
			} catch (NumberFormatException e1) {
				count=0;
			}
			//模式判断
			if(mode.contains("预付")) {
//				if(judge.contains("纯销")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				} else if(judge.contains("销售")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				}
//				if(tx.contains("Rx")) {//Rx&&T4
//					if(judge.contains("纯销")) {
//						daqu_cl = 0.1f;
//						space_cl = 0.5f;
//					}
//				}
				daqu_cl = 0.0f;
				space_cl = 0.0f;
			} else {
				if(judge.contains("纯销")) {
					daqu_cl = 0.1f;
					space_cl = 0.5f;
				} 
				if(tx.contains("Rx")) {//Rx&&T4
					if(judge.contains("纯销")) {
						daqu_cl = 0.1f;
						space_cl = 0.5f;
					}
				}
			}
			
			//晚交流向判断
			if(wjlx.contains("晚交流向")) {
				daqu_wj = -0.03f;
				space_wj = -0.1f;
			}
			//大区经理兼职片区经理时大区存量来源以及提成为0
			if(tcman.equals("张俊桥") || tcman.equals("周念") || tcman.equals("华俊") || tcman.equals("李丹")) {
				daqu_cl = 0.0f;
			}
			//崔海东无片区来源
//			if(tcman.contains("崔海东")) {
//				space_cl = 0.0f;
//			}
			
			String daqu_cl_tc = df.format(daqu_cl*count);
			String space_cl_tc =  df.format(space_cl*count);
			String daqu_wj_tc =  df.format(daqu_wj*count);
			String space_wj_tc =  df.format(space_wj*count);
			//初始化参数
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,0,0,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,0,0,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q2' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算OTC提成 备份Q2,类似Q2计算
	 * @throws SQLException 
	 */
	public void OTC_TC_Q1() throws SQLException {
		String id = "";
		String counts = "0";
		float count =0f;
		String qudao="";
		String tx="";
		String mode="";
		String judge="";
		//String space="";
		String wjlx="";
		String tcman="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,count count,terminaltype qudao, "
				+ " xieyizhuangtai tx,mode mode,judge judge,space space,money6 wjlx,tichengbelong tcman "
				+ " from kdb_nss_log_plans "
				+ " where judge in('纯销')"
				+ " and (xieyizhuangtai = 'OTC' "
				+ " or (xieyizhuangtai='Rx' and terminaltype='T4')) "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			counts = list.get(i)[1]==null?"0":list.get(i)[1].toString();//数量
			qudao = list.get(i)[2]==null?"":list.get(i)[2].toString();//渠道
			tx = list.get(i)[3]==null?"":list.get(i)[3].toString();//条线
			mode = list.get(i)[4]==null?"":list.get(i)[4].toString();//模式
			judge = list.get(i)[5]==null?"":list.get(i)[5].toString();//行为
			//space = list.get(i)[6]==null?"":list.get(i)[6].toString();//片区
			wjlx = list.get(i)[7]==null?"":list.get(i)[7].toString();//晚交流向
			tcman = list.get(i)[8]==null?"":list.get(i)[8].toString();//片区提成人
			//存量
			float daqu_cl = 0;
			float space_cl = 0;
			//晚交
			float daqu_wj = 0;
			float space_wj = 0;
			try {
				count = Float.parseFloat(counts);
			} catch (NumberFormatException e1) {
				count=0;
			}
			//模式判断
			if(mode.contains("预付")) {
//				if(judge.contains("纯销")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				} else if(judge.contains("销售")) {
//					daqu_cl = 0.0f;
//					space_cl = 0.0f;
//				}
//				if(tx.contains("Rx")) {//Rx&&T4
//					if(judge.contains("纯销")) {
//						daqu_cl = 0.0f;
//						space_cl = 0.0f;
//					}
//				}
				daqu_cl = 0.0f;
				space_cl = 0.0f;
			} else {
				if(judge.contains("纯销")) {
					daqu_cl = 0.1f;
					space_cl = 0.5f;
				} 
				if(tx.contains("Rx")) {//Rx&&T4
					if(judge.contains("纯销")) {
						daqu_cl = 0.1f;
						space_cl = 0.5f;
					}
				}
			}
			
			//晚交流向判断
			if(wjlx.contains("晚交流向")) {
				daqu_wj = -0.03f;
				space_wj = -0.1f;
			}
			//大区经理兼职片区经理时大区存量来源以及提成为0
			if(tcman.equals("张俊桥") || tcman.equals("周念") || tcman.equals("华俊") || tcman.equals("李丹")) {
				daqu_cl = 0.0f;
			}
			//崔海东无片区来源
//			if(tcman.contains("崔海东")) {
//				space_cl = 0.0f;
//			}
			
			String daqu_cl_tc = df.format(daqu_cl*count);
			String space_cl_tc =  df.format(space_cl*count);
			String daqu_wj_tc =  df.format(daqu_wj*count);
			String space_wj_tc =  df.format(space_wj*count);
			//初始化参数
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,0,0,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,0,0,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q1' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}

	/***
	 * 计算非新疆，Rx提成
	 * @throws SQLException 
	 */
	public void fxj_Rx_TCQ3() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String qudao="";
		String space="";
		String product="";
		String terminal="";
		String daqu="";
		String shengfen="";
		String wjlx="";
		String tcman="";
		String dqman="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,province province,product product,terminal terminal,daqu daqu,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province not like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			shengfen = list.get(i)[6]==null?"":list.get(i)[6].toString();//省份
			product = list.get(i)[7]==null?"":list.get(i)[7].toString();//品种
			terminal = list.get(i)[8]==null?"":list.get(i)[8].toString();//终端
			daqu = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区
			tcman = list.get(i)[10]==null?"":list.get(i)[10].toString();//片区提成人
			dqman = list.get(i)[11]==null?"":list.get(i)[11].toString();//大区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//存量
			float space_cl = 0;
			float space_zl = 0;
			//增量
			float daqu_cl = 0;
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			
			//累加各个片区实际完成量 
			if(summap.containsKey(space)) {
				summap.put(space, summap.get(space)==null?0:summap.get(space)+scount);
			} else {
				summap.put(space, scount+0.0);
			}
			
			//累加各个大区的实际完成量
			if(daqu_summap.containsKey(daqu)) {
				daqu_summap.put(daqu, daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu)+scount);
			} else {
				daqu_summap.put(daqu, scount+0.0);
			}
			
			double na = 100000*10000*10000;
			/***判断是否超出存量线**/
			//该【片区】实际完成的纯销量
			double sjtask = summap.get(space)==null?0:summap.get(space);
			//该【大区】实际完成的纯销量
			double daqu_sjtask = daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu);
			
			//该【片区】存量线
			double task = taskmap.get(space)==null?na:taskmap.get(space);
			//该【大区】存量线
			double daqu_task = daqu_taskmap.get(daqu)==null?na:daqu_taskmap.get(daqu);
			
			//计算片区增量和存量提成
			if(sjtask >= task) {
				space_zl = 0.6f;
			} else {
				space_cl = 0.4f;
			}
//			if(space.contains("粤闽")) {
//				System.out.println("片区任务："+taskmap.get(space)+";实际完成量："+summap.get(space));
//				System.out.println("大区任务："+daqu_taskmap.get(daqu)+";实际完成量："+daqu_summap.get(daqu));
//			}
			//计算大区增量和存量提成
			if(daqu_sjtask >= daqu_task) {
				daqu_zl = 0.2f;
			} else {
				daqu_cl = 0.1f;
			}
			
			//判断晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = 0;
				daqu_wj = -0.05f;
			}
			//省份包含北京&&模式为自营，片区存量1元/盒(折量)
			if(shengfen.contains("北京")&&mode.contains("自营")&&product.contains("A")) {
				space_cl = 1.0f;
			} 
			//大区经理兼职片区经理时，该片区没有大区来源。
			tcman = tcman == null?"":tcman;
			dqman = dqman == null?"":dqman;
			if(tcman.equals(dqman)) {
				daqu_cl = 0.0f;
				daqu_zl = 0.0f;
			}
			
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q3' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算非新疆，Rx提成
	 * @throws SQLException 
	 */
	public void fxj_Rx_TCQ4() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String qudao="";
		String space="";
		String product="";
		String terminal="";
		String daqu="";
		String shengfen="";
		String wjlx="";
		String tcman="";
		String dqman="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,province province,product product,terminal terminal,daqu daqu,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province not like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			shengfen = list.get(i)[6]==null?"":list.get(i)[6].toString();//省份
			product = list.get(i)[7]==null?"":list.get(i)[7].toString();//品种
			terminal = list.get(i)[8]==null?"":list.get(i)[8].toString();//终端
			daqu = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区
			tcman = list.get(i)[10]==null?"":list.get(i)[10].toString();//片区提成人
			dqman = list.get(i)[11]==null?"":list.get(i)[11].toString();//大区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//存量
			float space_cl = 0;
			float space_zl = 0;
			//增量
			float daqu_cl = 0;
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			
			//累加各个片区实际完成量 
			if(summap.containsKey(space)) {
				summap.put(space, summap.get(space)==null?0:summap.get(space)+scount);
			} else {
				summap.put(space, scount+0.0);
			}
			
			//累加各个大区的实际完成量
			if(daqu_summap.containsKey(daqu)) {
				daqu_summap.put(daqu, daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu)+scount);
			} else {
				daqu_summap.put(daqu, scount+0.0);
			}
			
			double na = 100000*10000*10000;
			/***判断是否超出存量线**/
			//该【片区】实际完成的纯销量
			double sjtask = summap.get(space)==null?0:summap.get(space);
			//该【大区】实际完成的纯销量
			double daqu_sjtask = daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu);
			
			//该【片区】存量线
			double task = taskmap.get(space)==null?na:taskmap.get(space);
			//该【大区】存量线
			double daqu_task = daqu_taskmap.get(daqu)==null?na:daqu_taskmap.get(daqu);
			
			
			//计算片区增量和存量提成
			if(sjtask >= task) {
				space_zl = 0.6f;
			} else {
				space_cl = 0.4f;
			}
//			if(space.contains("粤闽")) {
//				System.out.println("片区任务："+taskmap.get(space)+";实际完成量："+summap.get(space));
//				System.out.println("大区任务："+daqu_taskmap.get(daqu)+";实际完成量："+daqu_summap.get(daqu));
//			}
			//计算大区增量和存量提成
			if(daqu_sjtask >= daqu_task) {
				daqu_zl = 0.2f;
			} else {
				daqu_cl = 0.1f;
			}
			
			//判断晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = 0;
				daqu_wj = -0.05f;
			}
			//省份包含北京&&模式为自营，片区存量1元/盒(折量)
			if(shengfen.contains("北京")&&mode.contains("自营")&&product.contains("A")) {
				space_cl = 1.0f;
			} 
			//大区经理兼职片区经理时，该片区没有大区来源。
			tcman = tcman == null?"":tcman;
			dqman = dqman == null?"":dqman;
			if(tcman.equals(dqman)) {
				daqu_cl = 0.0f;
				daqu_zl = 0.0f;
			}
			
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q4' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算非新疆，Rx提成 官长
	 * @throws SQLException 
	 * 官长的提成：存量提成：通过【高价来源】字段体现，增量提成：通过【主管增量来源】字段体现。
	 */
	public void fxj_Rx_gc_TC() throws SQLException {
		//存量
		Map<String,Double> summapGC = new LinkedHashMap<String,Double>();
		//实际完成
		Map<String,Double> sjsumGC = new LinkedHashMap<String,Double>();
		
		String clSql = " and DATE_FORMAT(sdate,'%Y%m%d')"
				+ " BETWEEN DATE_FORMAT('"+(year-1)+"/04/18','%Y%m%d') "
				+ " AND DATE_FORMAT('"+(year-1)+"/12/05','%Y%m%d') "
				+ " and product in ('Y','Z') and province not in ('北京','新疆','天津')"
				+ " AND xieyizhuangtai = 'Rx' AND judge='纯销'";
		
		String sjSql = " and DATE_FORMAT(sdate,'%Y%m%d')"
				+ " BETWEEN DATE_FORMAT('"+year+"/04/18','%Y%m%d') "
				+ " AND DATE_FORMAT('"+year+"/12/05','%Y%m%d') "
				+ " and product in ('Y','Z') and province not in ('北京','新疆','天津')"
				+ " AND xieyizhuangtai = 'Rx' AND judge='纯销'";
		
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String qudao="";
		String space="";
		String product="";
		String terminal="";
		String daqu="";
		String shengfen="";
		String wjlx="";
		String tcman="";
		String dqman="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		
		//查询存量线12/31: 96451 				72432
		String sqlall = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE 1=1 "+clSql;
		List<TcTable> listsj = query.query(sqlall, new BeanListHandler<TcTable>(TcTable.class));
		for (TcTable tcTable : listsj) {
			summapGC.put("cl2017",tcTable.getTask_18());
		}
		//System.out.println("存量sql:"+sqlall);
		
		//获取4.18开始的每条流向12/31: 120665 97742
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,province province,product product,terminal terminal,daqu daqu,tichengbelong tcman,daquTcMan dqman "
				+ " from kdb_nss_log_plans "
				+ " where 1=1 "+sjSql;
		
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		
		//System.out.println("实际sql:"+sql);
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			shengfen = list.get(i)[6]==null?"":list.get(i)[6].toString();//省份
			product = list.get(i)[7]==null?"":list.get(i)[7].toString();//品种
			terminal = list.get(i)[8]==null?"":list.get(i)[8].toString();//终端
			daqu = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区
			tcman = list.get(i)[10]==null?"":list.get(i)[10].toString();//片区提成人
			dqman = list.get(i)[11]==null?"":list.get(i)[11].toString();//大区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//高阶来源
			float gaoJieDanwei = 0;
			//主管增量来源
			float zgDanwei_zl = 0;
			
			double task = summapGC.get("cl2017");
			//System.out.println("2017存量："+task);
			sjsumGC.put("cl2017", sjsumGC.get("cl2017")==null?0:sjsumGC.get("cl2017")+scount);
			
			/***判断是否超出存量线**/
			//该【全国】实际完成的纯销量
			double sjtask = sjsumGC.get("cl2017");
			
			//计算增量和存量提成
			if(sjtask >= task) {
				zgDanwei_zl = 0.3f;
			} else {
				gaoJieDanwei = 0.15f;
			}
			//初始化参数
			gaoJieDanwei = Float.parseFloat(df.format(gaoJieDanwei));
			zgDanwei_zl = Float.parseFloat(df.format(zgDanwei_zl));
			
			String gaoJieTc = df.format(gaoJieDanwei*scount);
			String zgTc_zl = df.format(zgDanwei_zl*scount);
			params[i] = new Object[] {
					gaoJieDanwei,gaoJieTc,
					zgDanwei_zl,zgTc_zl,
					id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set  "
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=? "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	
	/***
	 * 计算非新疆，Rx提成
	 * @throws SQLException 
	 */
	public void fxj_Rx_TC_Q2() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String qudao="";
		String space="";
		String product="";
		String terminal="";
		String daqu="";
		String tcman="";
		String dqman="";
		String shengfen="";
		String wjlx="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,province province,product product,terminal terminal,daqu daqu,tichengbelong,daquTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province not like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx' and terminaltype!='T4') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			shengfen = list.get(i)[6]==null?"":list.get(i)[6].toString();//省份
			product = list.get(i)[7]==null?"":list.get(i)[7].toString();//品种
			terminal = list.get(i)[8]==null?"":list.get(i)[8].toString();//终端
			daqu = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区
			tcman = list.get(i)[10]==null?"":list.get(i)[10].toString();//片区提成人
			dqman = list.get(i)[11]==null?"":list.get(i)[11].toString();//大区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//存量
			float space_cl = 0;
			float space_zl = 0;
			//增量
			float daqu_cl = 0;
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			
			//累加各个片区实际完成量
			if(summap.containsKey(space)) {
				summap.put(space, summap.get(space)==null?0:summap.get(space)+scount);
			} else {
				summap.put(space, scount+0.0);
			}
			
			//累加各个大区的实际完成量
			if(daqu_summap.containsKey(daqu)) {
				daqu_summap.put(daqu, daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu)+scount);
			} else {
				daqu_summap.put(daqu, scount+0.0);
			}
			/***判断是否超出存量线**/
			//该【片区】实际完成的纯销量
			double sjtask = summap.get(space)==null?0:summap.get(space);
			//该【大区】实际完成的纯销量
			double daqu_sjtask = daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu);
			
			//该【片区】存量线
			double task = taskmap.get(space)==null?0:taskmap.get(space);
			//该【大区】存量线
			double daqu_task = daqu_taskmap.get(daqu)==null?0:daqu_taskmap.get(daqu);
			
			//计算片区增量和存量提成
			if(sjtask >= task) {
				space_zl = 0.6f;
			} else {
				space_cl = 0.4f;
			}
			
			//计算大区增量和存量提成
			if(daqu_sjtask >= daqu_task) {
				daqu_zl = 0.2f;
			} else {
				daqu_cl = 0.1f;
			}
			
			//判断晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = -0.1f;
				daqu_wj = -0.03f;
			}
			//省份包含北京&&模式为自营，片区存量1元/盒(折量)
			if(shengfen.contains("北京")&&mode.contains("自营")&&product.contains("A")) {
				space_cl = 1.0f;
			} 
			//左亚杰
//			if(terminal.contains("北京市昌平区中医医院【本院】") || terminal.contains("首都医科大学附属北京友谊医院（中药）")) {
//				space_cl = 1.0f;
//			}
			//大区经理兼职片区经理时，片区来源-0.1。
//			if(jianzhimap.containsKey(space)) {
//				double j = jianzhimap.get(space)==null?0:jianzhimap.get(space);
//				if(j == 1) {
//					space_cl = (space_cl - 0.1f)<0?0:(space_cl - 0.1f);
//					space_zl = (space_zl - 0.1f)<0?0:(space_zl - 0.1f);
//				}
//			}
			tcman = tcman == null?"":tcman;
			dqman = dqman == null?"":dqman;
			if(tcman.equals(dqman)) {
				space_cl = (space_cl - 0.1f)<0?0:(space_cl - 0.1f);
				space_zl = (space_zl - 0.1f)<0?0:(space_zl - 0.1f);
			}
			
			//省份不包含新疆&&省份不包含北京&&品种为Y 或者 品种为Z时，大区来源-0.05，片区来源-0.2。
			if(!shengfen.contains("新疆")&&!shengfen.contains("北京")&&product.contains("Y")) {
				space_cl = (space_cl - 0.2f)<0?0:(space_cl - 0.2f);
				space_zl = (space_zl - 0.2f)<0?0:(space_zl - 0.2f);
				daqu_cl = (daqu_cl - 0.05f)<0?0:(daqu_cl - 0.05f);
				daqu_zl = (daqu_zl - 0.05f)<0?0:(daqu_zl - 0.05f);
			}
			if(product.contains("Z")) {
				space_cl = (space_cl - 0.2f)<0?0:(space_cl - 0.2f);
				space_zl = (space_zl - 0.2f)<0?0:(space_zl - 0.2f);
				daqu_cl = (daqu_cl - 0.05f)<0?0:(daqu_cl - 0.05f);
				daqu_zl = (daqu_zl - 0.05f)<0?0:(daqu_zl - 0.05f);
			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q2' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	
	/***
	 * 计算非新疆，Rx提成
	 * @throws SQLException 
	 */
	public void fxj_Rx_TC_Q1() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String qudao="";
		String space="";
		String product="";
		String terminal="";
		String daqu="";
		String tcman="";
		String dqman="";
		String shengfen="";
		String wjlx="";
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,province province,product product,terminal terminal,daqu daqu,tichengbelong,daquTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province not like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx' and terminaltype!='T4') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			shengfen = list.get(i)[6]==null?"":list.get(i)[6].toString();//省份
			product = list.get(i)[7]==null?"":list.get(i)[7].toString();//品种
			terminal = list.get(i)[8]==null?"":list.get(i)[8].toString();//终端
			daqu = list.get(i)[9]==null?"":list.get(i)[9].toString();//大区
			tcman = list.get(i)[10]==null?"":list.get(i)[10].toString();//片区提成人
			dqman = list.get(i)[11]==null?"":list.get(i)[11].toString();//大区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//存量
			float space_cl = 0;
			float space_zl = 0;
			//增量
			float daqu_cl = 0;
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			
			//累加各个片区实际完成量
			if(summap.containsKey(space)) {
				summap.put(space, summap.get(space)==null?0:summap.get(space)+scount);
			} else {
				summap.put(space, scount+0.0);
			}
			
			//累加各个大区的实际完成量
			if(daqu_summap.containsKey(daqu)) {
				daqu_summap.put(daqu, daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu)+scount);
			} else {
				daqu_summap.put(daqu, scount+0.0);
			}
			/***判断是否超出存量线**/
			//该【片区】实际完成的纯销量
			double sjtask = summap.get(space)==null?0:summap.get(space);
			//该【大区】实际完成的纯销量
			double daqu_sjtask = daqu_summap.get(daqu)==null?0:daqu_summap.get(daqu);
			
			//该【片区】存量线
			double task = taskmap.get(space)==null?0:taskmap.get(space);
			//该【大区】存量线
			double daqu_task = daqu_taskmap.get(daqu)==null?0:daqu_taskmap.get(daqu);
			
			//计算片区增量和存量提成
			if(sjtask >= task) {
				space_zl = 0.6f;
			} else {
				space_cl = 0.4f;
			}
			
			//计算大区增量和存量提成
			if(daqu_sjtask >= daqu_task) {
				daqu_zl = 0.2f;
			} else {
				daqu_cl = 0.1f;
			}
			
			//判断晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = -0.1f;
				daqu_wj = -0.03f;
			}
			//省份包含北京&&模式为自营，片区存量1元/盒(折量)
			if(shengfen.contains("北京")&&mode.contains("自营")&&product.contains("A")) {
				space_cl = 1.0f;
			} 
			//左亚杰
//			if(terminal.contains("北京市昌平区中医医院【本院】") || terminal.contains("首都医科大学附属北京友谊医院（中药）")) {
//				space_cl = 1.0f;
//			}
			//大区经理兼职片区经理时，片区来源-0.1。
//			if(jianzhimap.containsKey(space)) {
//				double j = jianzhimap.get(space)==null?0:jianzhimap.get(space);
//				if(j == 1) {
//					space_cl = (space_cl - 0.1f)<0?0:(space_cl - 0.1f);
//					space_zl = (space_zl - 0.1f)<0?0:(space_zl - 0.1f);
//				}
//			}
			tcman = tcman == null?"":tcman;
			dqman = dqman == null?"":dqman;
			if(tcman.equals(dqman)) {
				space_cl = (space_cl - 0.1f)<0?0:(space_cl - 0.1f);
				space_zl = (space_zl - 0.1f)<0?0:(space_zl - 0.1f);
			}
			
			//省份不包含新疆&&省份不包含北京&&品种为Y 或者 品种为Z时，大区来源-0.05，片区来源-0.2。
			if(!shengfen.contains("新疆")&&!shengfen.contains("北京")&&product.contains("Y")) {
				space_cl = (space_cl - 0.2f)<0?0:(space_cl - 0.2f);
				space_zl = (space_zl - 0.2f)<0?0:(space_zl - 0.2f);
				daqu_cl = (daqu_cl - 0.05f)<0?0:(daqu_cl - 0.05f);
				daqu_zl = (daqu_zl - 0.05f)<0?0:(daqu_zl - 0.05f);
			}
			if(product.contains("Z")) {
				space_cl = (space_cl - 0.2f)<0?0:(space_cl - 0.2f);
				space_zl = (space_zl - 0.2f)<0?0:(space_zl - 0.2f);
				daqu_cl = (daqu_cl - 0.05f)<0?0:(daqu_cl - 0.05f);
				daqu_zl = (daqu_zl - 0.05f)<0?0:(daqu_zl - 0.05f);
			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			params[i] = new Object[] {0,0,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,0,0,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					0,0,0,0,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q1' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	
	
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xj_Rx_TC() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String space="";
		String product="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		//詹奇兵的基础任务量
		float zqb_task = 10*10000*10000f;
		//新疆T1的任务量
		float t1_task = 20*10000*10000f;
		//新疆全省的任务量
		float total_task = 80*10000*10000f;
		//查询当前季度 新疆 Rx纯销 流向
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//片区存量
			float space_cl = 0;
			//片区增量
			float space_zl = 0;
			//大区存量
			float daqu_cl = 0;
			//大区增量
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			//高阶来源
			float gj = 0;
			//贡献来源
			float gx = 0;
			//区域主管来源
			float zg_cl = 0;
			float zg_zl = 0;
			
			/***片区来源计算start
			 */
			//区域主管来源
//			if(space.contains("新疆喀什")) {
//				if(xjsummap.containsKey(space)) {
//					double zqb_sj_task = xjsummap.get(space)==null?0:xjsummap.get(space);
//					if(zqb_sj_task>=zqb_task) {//区域主管来源增量
//						zg_zl = 0.5f;
//					}else {//区域主管来源存量
//						zg_cl = 0.3f;
//					}
//				}
//			} 
			
			double na = 100000*10000*1000;
			//获取片区高阶任务
			double gjtask = xjGsummap.get(space)==null?na:xjGsummap.get(space);
			//获取片区基础任务
			double jctask = xjBsummap.get(space)==null?na:xjBsummap.get(space);
			
			//各个片区实际完成量(一次性查询出来) 用于计算T3渠道提成
			double sjtask = xjsummap.get(space)==null?0:xjsummap.get(space);
			
			//累加各个片区实际完成量  用于计算T1渠道提成
			if(xjsummap_t1.containsKey(space)) {
				xjsummap_t1.put(space, xjsummap_t1.get(space)==null?0:xjsummap_t1.get(space)+scount);
			} else {
				xjsummap_t1.put(space, scount+0.0);
			}
			
			//渠道判断，计算T3，
			if(qudao.contains("T3")) {
				if(sjtask >= gjtask) {//高阶来源
					if("自营".equals(mode)) {
						gj = 1.5f;
					} else if(mode.contains("小包")) {
						gj = 1.0f;
					}
				} else if(sjtask >= jctask) {//增量来源,完成基础任务的提成
					if("自营".equals(mode)) {
						space_zl =  1.0f;
					} else if(mode.contains("小包")) {
						space_zl =  0.5f;
					}
				} else {//存量来源,未完成基础任务的提成
					if("自营".equals(mode)) {
						space_cl =  0.8f;
					} else if(mode.contains("小包")) {
						space_cl =  0.3f;
					}
				}
			} else if(qudao.contains("T1")) {//计算T1
				if(sjtask >= gjtask) {//T1时，如果完成了高价任务，则超出+未超出都是1
					space_zl =  1.0f;
					space_cl =  0.0f;
				} else {//T1时，如果未完成了高价任务，完成基础任务，则超出部分是1，未超出部分是0.5
					if(xjsummap_t1.get(space) >= jctask) {//增量来源
						space_zl =  1.0f;
						space_cl =  0.0f;
					} else {//存量来源
						space_cl =  0.5f;
						space_zl =  0.0f;
					}
				}
			}
			//晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = space_Rx;
				daqu_wj = daqu_Rx;
			} 
			//崔海东无片区来源
//			if(space.contains("新疆直属1")) {
//				space_cl = 0.0f;
//			}
			/***片区来源计算end
			 */
			
			//大区来源 计算
			//查询新疆全年实际完成量
//			double sjTotal = xjTotalsummap.get("xjtotal")==null?0:xjTotalsummap.get("xjtotal");
//			if(sjTotal >= total_task) {
//				daqu_zl = 0.4f;
//			} else {
//				daqu_cl = 0.2f;
//			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			gj = Float.parseFloat(df.format(gj));
			gx = Float.parseFloat(df.format(gx));
			zg_cl = Float.parseFloat(df.format(zg_cl));
			zg_zl = Float.parseFloat(df.format(zg_zl));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			String gj_tc = df.format(gj*scount);
			String gx_tc = df.format(gx*scount);
			String zg_cl_tc = df.format(zg_cl*scount);
			String zg_zl_tc = df.format(zg_zl*scount);
			
			params[i] = new Object[] {gx,gx_tc,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,gj,gj_tc,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					zg_cl,zg_cl_tc,zg_zl,zg_zl_tc,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xj_Rx_TCQ3() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String space="";
		String product="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		//詹奇兵的基础任务量
		float zqb_task = 10*10000*10000f;
		//新疆T1的任务量
		float t1_task = 20*10000*10000f;
		//新疆全省的任务量
		float total_task = 80*10000*10000f;
		//查询当前季度 新疆 Rx纯销 流向
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//片区存量
			float space_cl = 0;
			//片区增量
			float space_zl = 0;
			//大区存量
			float daqu_cl = 0;
			//大区增量
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			//高阶来源
			float gj = 0;
			//贡献来源
			float gx = 0;
			//区域主管来源
			float zg_cl = 0;
			float zg_zl = 0;
			
			/***片区来源计算start
			 */
			//区域主管来源
//			if(space.contains("新疆喀什")) {
//				if(xjsummap.containsKey(space)) {
//					double zqb_sj_task = xjsummap.get(space)==null?0:xjsummap.get(space);
//					if(zqb_sj_task>=zqb_task) {//区域主管来源增量
//						zg_zl = 0.5f;
//					}else {//区域主管来源存量
//						zg_cl = 0.3f;
//					}
//				}
//			} 
			
			double na = 100000*10000*1000*10000;
			//获取片区高阶任务
			double gjtask = na;
			//获取片区基础任务
			double jctask = na;
			
			//各个片区实际完成量(一次性查询出来) 用于计算T3渠道提成
			//double sjtask = xjsummap.get(space)==null?0:xjsummap.get(space);
			double sjtask = 0;
			//T1的完成量
			double sjtaskT1 = 0;
			
			//累加各个片区实际完成量  用于计算T1渠道提成
//			if(xjsummap_t1.containsKey(space)) {
//				xjsummap_t1.put(space, xjsummap_t1.get(space)==null?0:xjsummap_t1.get(space)+scount);
//			} else {
//				xjsummap_t1.put(space, scount+0.0);
//			}
			
			//渠道判断，计算T3，
			if(qudao.contains("T3")) {
				if(sjtask >= gjtask) {//高阶来源
					if("自营".equals(mode)) {
						gj = 1.5f;
					} else if(mode.contains("小包")) {
						gj = 1.0f;
					}
				} else if(sjtask >= jctask) {//增量来源,完成基础任务的提成
					if("自营".equals(mode)) {
						space_zl =  1.0f;
					} else if(mode.contains("小包")) {
						space_zl =  0.5f;
					}
				} else {//存量来源,未完成基础任务的提成
					if("自营".equals(mode)) {
						space_cl =  0.8f;
					} else if(mode.contains("小包")) {
						space_cl =  0.3f;
					}
				}
			} else if(qudao.contains("T1")) {//计算T1
				if(sjtaskT1 >= gjtask) {//T1时，如果完成了高价任务，则超出+未超出都是1
					space_zl =  1.0f;
					space_cl =  0.0f;
				} else {//T1时，如果未完成了高价任务，完成基础任务，则超出部分是1，未超出部分是0.5
					if(sjtaskT1 >= jctask) {//增量来源
						space_zl =  1.0f;
						space_cl =  0.0f;
					} else {//存量来源
						space_cl =  0.5f;
						space_zl =  0.0f;
					}
				}
			}
			//晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = 0;
				daqu_wj = -0.05f;
			} 
			//崔海东无片区来源
//			if(space.contains("新疆直属1")) {
//				space_cl = 0.0f;
//			}
			/***片区来源计算end
			 */
			
			//大区来源 计算
			//查询新疆全年实际完成量
//			double sjTotal = xjTotalsummap.get("xjtotal")==null?0:xjTotalsummap.get("xjtotal");
//			if(sjTotal >= total_task) {
//				daqu_zl = 0.4f;
//			} else {
//				daqu_cl = 0.2f;
//			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			gj = Float.parseFloat(df.format(gj));
			gx = Float.parseFloat(df.format(gx));
			zg_cl = Float.parseFloat(df.format(zg_cl));
			zg_zl = Float.parseFloat(df.format(zg_zl));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			String gj_tc = df.format(gj*scount);
			String gx_tc = df.format(gx*scount);
			String zg_cl_tc = df.format(zg_cl*scount);
			String zg_zl_tc = df.format(zg_zl*scount);
			
			params[i] = new Object[] {gx,gx_tc,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,gj,gj_tc,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					zg_cl,zg_cl_tc,zg_zl,zg_zl_tc,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q3' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xj_Rx_TC_Q2() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String space="";
		String product="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		//詹奇兵的基础任务量
		float zqb_task = 10*10000f;
		//新疆T1的任务量
		float t1_task = 20*10000f;
		//新疆全省的任务量
		float total_task = 80*10000f;
		//查询当前季度 新疆 Rx非T4 纯销 流向
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx' and terminaltype!='T4') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//片区存量
			float space_cl = 0;
			//片区增量
			float space_zl = 0;
			//大区存量
			float daqu_cl = 0;
			//大区增量
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			//高阶来源
			float gj = 0;
			//贡献来源
			float gx = 0;
			//区域主管来源
			float zg_cl = 0;
			float zg_zl = 0;
			
			/***片区来源计算start
			 */
			//区域主管来源
			if(space.contains("新疆喀什2")&&zgTcMan.contains("詹奇兵")) {
//				if(xjsummap.containsKey(space)) {
//					double zqb_sj_task = xjsummap.get(space)==null?0:xjsummap.get(space);
//					if(zqb_sj_task>=zqb_task) {//区域主管来源增量
//						zg_zl = 0.5f;
//					}else {//区域主管来源存量
//						zg_cl = 0.3f;
//					}
//				}
				zg_cl = 0.3f;
			} 
			
			//渠道判断
			if(qudao.contains("T3")) {
				double na = 10000*100000*10000;
				//判断是否完成高阶任务
				//double gjtask = xjGsummap.get(space)==null?0:xjGsummap.get(space);
				double gjtask = na;
				//基础任务
				//double jctask = xjBsummap.get(space)==null?0:xjBsummap.get(space);
				double jctask = na;
				//实际完成量
				//double sjtask = xjsummap.get(space)==null?0:xjsummap.get(space);
				double sjtask = 0;
				if(sjtask >= gjtask) {//高阶来源
					if(mode.contains("自营")) {
						gj = 1.5f;
					} else if(mode.contains("小包")) {
						gj = 1.0f;
					}
				} else if(sjtask >= jctask) {//增量来源
					if(mode.contains("自营")) {
						space_zl =  1.0f;
					} else if(mode.contains("小包")) {
						space_zl =  0.5f;
					}
				} else {//存量来源
					if(mode.contains("自营")) {
						space_cl =  0.8f;
					} else if(mode.contains("小包")) {
						space_cl =  0.3f;
					}
				}
			} else if(qudao.contains("T1")) {
				//贡献来源
				if(gxTcMan.contains("常莉") || gxTcMan.contains("付旭心") 
						||gxTcMan.contains("拜合提亚尔")||gxTcMan.contains("杨坤")) {
					gx = 0.5f;
				} 
				
				//新疆T1的实际完成量
				//double sjtask = xjT1summap.get("t1")==null?0:xjT1summap.get("t1");
				double sjtask = 0;
				if(sjtask >= t1_task) {
					space_zl = 1.0f;
				} else {
					space_cl = 0.5f;
				}
			}
			//晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = -0.1f;
				daqu_wj = -0.03f;
			} 
			//崔海东无片区来源
//			if(space.contains("新疆直属1")) {
//				space_cl = 0.0f;
//			}
			/***片区来源计算end
			 */
			
			//大区来源 计算
			//查询新疆全年实际完成量
//			double sjTotal = xjTotalsummap.get("xjtotal")==null?0:xjTotalsummap.get("xjtotal");
//			if(sjTotal >= total_task) {
//				daqu_zl = 0.4f;
//			} else {
//				daqu_cl = 0.2f;
//			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			gj = Float.parseFloat(df.format(gj));
			gx = Float.parseFloat(df.format(gx));
			zg_cl = Float.parseFloat(df.format(zg_cl));
			zg_zl = Float.parseFloat(df.format(zg_zl));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			String gj_tc = df.format(gj*scount);
			String gx_tc = df.format(gx*scount);
			String zg_cl_tc = df.format(zg_cl*scount);
			String zg_zl_tc = df.format(zg_zl*scount);
			
			params[i] = new Object[] {gx,gx_tc,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,gj,gj_tc,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					zg_cl,zg_cl_tc,zg_zl,zg_zl_tc,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q2' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xj_Rx_TC_Q1() throws SQLException {
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		String mode="";
		String space="";
		String product="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		//詹奇兵的基础任务量
		float zqb_task = 10*10000f;
		//新疆T1的任务量
		float t1_task = 20*10000f;
		//新疆全省的任务量
		float total_task = 80*10000f;
		//查询当前季度 新疆 Rx非T4 纯销 流向
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx' and terminaltype!='T4') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			//片区存量
			float space_cl = 0;
			//片区增量
			float space_zl = 0;
			//大区存量
			float daqu_cl = 0;
			//大区增量
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			//高阶来源
			float gj = 0;
			//贡献来源
			float gx = 0;
			//区域主管来源
			float zg_cl = 0;
			float zg_zl = 0;
			
			/***片区来源计算start
			 */
			//区域主管来源
			if(space.contains("新疆喀什2")&&zgTcMan.contains("詹奇兵")) {
//				if(xjsummap.containsKey(space)) {
//					double zqb_sj_task = xjsummap.get(space)==null?0:xjsummap.get(space);
//					if(zqb_sj_task>=zqb_task) {//区域主管来源增量
//						zg_zl = 0.5f;
//					}else {//区域主管来源存量
//						zg_cl = 0.3f;
//					}
//				}
				zg_cl = 0.3f;
			} 
			
			//渠道判断
			if(qudao.contains("T3")) {
				double na = 10000*100000*10000;
				//判断是否完成高阶任务
				//double gjtask = xjGsummap.get(space)==null?0:xjGsummap.get(space);
				double gjtask = na;
				//基础任务
				//double jctask = xjBsummap.get(space)==null?0:xjBsummap.get(space);
				double jctask = na;
				//实际完成量
				//double sjtask = xjsummap.get(space)==null?0:xjsummap.get(space);
				double sjtask = 0;
				if(sjtask >= gjtask) {//高阶来源
					if(mode.contains("自营")) {
						gj = 1.5f;
					} else if(mode.contains("小包")) {
						gj = 1.0f;
					}
				} else if(sjtask >= jctask) {//增量来源
					if(mode.contains("自营")) {
						space_zl =  1.0f;
					} else if(mode.contains("小包")) {
						space_zl =  0.5f;
					}
				} else {//存量来源
					if(mode.contains("自营")) {
						space_cl =  0.8f;
					} else if(mode.contains("小包")) {
						space_cl =  0.3f;
					}
				}
			} else if(qudao.contains("T1")) {
				//贡献来源
				if(gxTcMan.contains("常莉") || gxTcMan.contains("付旭心") 
						||gxTcMan.contains("拜合提亚尔")||gxTcMan.contains("杨坤")) {
					gx = 0.5f;
				} 
				
				//新疆T1的实际完成量
				//double sjtask = xjT1summap.get("t1")==null?0:xjT1summap.get("t1");
				double sjtask = 0;
				if(sjtask >= t1_task) {
					space_zl = 1.0f;
				} else {
					space_cl = 0.5f;
				}
			}
			//晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = -0.1f;
				daqu_wj = -0.03f;
			} 
			//崔海东无片区来源
//			if(space.contains("新疆直属1")) {
//				space_cl = 0.0f;
//			}
			/***片区来源计算end
			 */
			
			//大区来源 计算
			//查询新疆全年实际完成量
//			double sjTotal = xjTotalsummap.get("xjtotal")==null?0:xjTotalsummap.get("xjtotal");
//			if(sjTotal >= total_task) {
//				daqu_zl = 0.4f;
//			} else {
//				daqu_cl = 0.2f;
//			}
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			gj = Float.parseFloat(df.format(gj));
			gx = Float.parseFloat(df.format(gx));
			zg_cl = Float.parseFloat(df.format(zg_cl));
			zg_zl = Float.parseFloat(df.format(zg_zl));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			String gj_tc = df.format(gj*scount);
			String gx_tc = df.format(gx*scount);
			String zg_cl_tc = df.format(zg_cl*scount);
			String zg_zl_tc = df.format(zg_zl*scount);
			
			params[i] = new Object[] {gx,gx_tc,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,gj,gj_tc,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					zg_cl,zg_cl_tc,zg_zl,zg_zl_tc,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q1' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	
	
	@RequestMapping(value="/q1")
	@ResponseBody
	public Msg y2018tc1() {
		Msg msg = null;
		try {
			long start = System.currentTimeMillis();
			init(2018,1);
			OTC_TC_Q1();//计算OTC
			fxj_Rx_TC_Q1();//非新疆Rx提成
			xj_Rx_TC_Q1();//计算新疆Rx提成 
			//xj_Rx_TC_T1();//计算新疆Rx提成 T1
			long end = System.currentTimeMillis();
			System.out.println("Q1提成计算花时："+(end-start)/1000);
			msg = new Msg(Constant.SUCESSFUL_CODE, "Q1提成计算完成，花时："+(end-start)/1000+"秒");
		} catch (Exception e) {
			e.printStackTrace();
			msg = new Msg(Constant.FAIL_CODE,Constant.FAIL_MSG+e.getMessage());
		}
		return msg;
	}
	
	@RequestMapping(value="/q2")
	@ResponseBody
	public Msg y2018tc2() {
		Msg msg = null;
		try {
			long start = System.currentTimeMillis();
			init(2018,2);
			OTC_TC_Q2();//计算OTC
			fxj_Rx_TC_Q2();//非新疆Rx提成
			xj_Rx_TC_Q2();//计算新疆Rx提成
			long end = System.currentTimeMillis();
			System.out.println("Q2提成计算花时："+(end-start)/1000);
			msg = new Msg(Constant.SUCESSFUL_CODE, "Q2提成计算完成，花时："+(end-start)/1000+"秒");
		} catch (Exception e) {
			e.printStackTrace();
			msg = new Msg(Constant.FAIL_CODE,Constant.FAIL_MSG+e.getMessage());
		}
		return msg;
	}
	
	/***
	 * 20180630版本，新疆都按照完不成任务来计算
	 * @return
	 */
	@RequestMapping(value="/q3")
	@ResponseBody
	public Msg y2018tc3() {//TODO
		Msg msg = null;
		try {
			long start = System.currentTimeMillis();
			init(2018,3);
			OTC_TC_Q3();//计算OTC
			fxj_Rx_TCQ3();//非新疆Rx提成
			xj_Rx_TCQ3();//计算新疆Rx提成
			long end = System.currentTimeMillis();
			System.out.println("Q3提成计算花时："+(end-start)/1000);
			msg = new Msg(Constant.SUCESSFUL_CODE, "Q3提成计算完成，花时："+(end-start)/1000+"秒");
		} catch (Exception e) {
			e.printStackTrace();
			msg = new Msg(Constant.FAIL_CODE,Constant.FAIL_MSG+e.getMessage());
		}
		return msg;
	}
	
	
	/***
	 * 20180630版本，新疆按照9~12月政策调整文件计算。
	 * @return
	 */
	@RequestMapping(value="/q4")
	@ResponseBody
	public Msg y2018tc4() {//TODO
		Msg msg = null;
		try {
			long start = System.currentTimeMillis();
			init(2018,4);
			OTC_TC_Q4();//计算OTC
			fxj_Rx_TCQ4();//非新疆Rx提成
			xjRXTCQ4();//计算新疆Rx提成
			fxj_Rx_gc_TC();//非新疆Rx官长提成
			xjRxTCwcTask();//新疆Rx 完成任务后的计算
			long end = System.currentTimeMillis();
			System.out.println("Q4提成计算花时："+(end-start)/1000);
			msg = new Msg(Constant.SUCESSFUL_CODE, "Q4提成计算完成，花时："+(end-start)/1000+"秒");
		} catch (Exception e) {
			e.printStackTrace();
			msg = new Msg(Constant.FAIL_CODE,Constant.FAIL_MSG+e.getMessage());
		}
		return msg;
	}
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xjRXTCQ4() throws SQLException {
		// 新疆9-12月的任务
		String xjzs1 = "新疆直属1";
		int xjzs1_count = 49500;
		String xjybt = "新疆伊博塔";
		int xjybt_count = 63200;
		String xjzs2 = "新疆直属2";
		int xjzs2_count = 36100;
		String xjaks = "新疆阿克苏";
		int xjaks_count = 29400;
		String xjbz = "新疆巴州";
		int xjbz_count = 32000;
		String xjht = "新疆和田";
		int xjht_count = 33000;
		String xjks = "新疆喀什";
		int xjks_count = 30000;
	
		/**9-12月 key=片区,value=当前新疆实际完成量**/
		Map<String,Double> curSum912 = new LinkedHashMap<String, Double>(64);
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String curSql = "SELECT SPACE space,CEIL(SUM(xsScount)) task_18 FROM `kdb_nss_log_plans` WHERE YEAR = '"+year+"' AND xieyizhuangtai = 'Rx' AND judge='纯销' AND INSTR(province,'新疆')>=1 "+whereSql+" GROUP BY SPACE";
		
		List<TcTable> listCur = query.query(curSql, new BeanListHandler<TcTable>(TcTable.class));
		for (TcTable tcTable : listCur) {
			curSum912.put(tcTable.getSpace(),tcTable.getTask_18());
			System.out.println(tcTable.getSpace()+"--"+curSum912.get(tcTable.getSpace()));
		}
		
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		float countd=0f;
		String mode="";
		String space="";
		String product="";
		String pack="";
		String count="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		String tichengbelong="";
		//查询当前季度 新疆 Rx纯销 流向
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan,product,pack,count,tichengbelong "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') "+andSql;
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			product = list.get(i)[8]==null?"":list.get(i)[8].toString();//品种
			pack = list.get(i)[9]==null?"":list.get(i)[9].toString();//包装
			count = list.get(i)[10]==null?"":list.get(i)[10].toString();//数量
			tichengbelong = list.get(i)[11]==null?"":list.get(i)[11].toString();//片区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			try {
				countd = Float.parseFloat(count);
			} catch (NumberFormatException e1) {
				countd=0;
			}
			//片区存量，未达成
			float space_cl = 0;
			//片区增量,达成
			float space_zl = 0;
			//大区存量
			float daqu_cl = 0;
			//大区增量
			float daqu_zl = 0;
			//晚交流向
			float space_wj = 0;
			float daqu_wj = 0;
			//高阶来源
			float gj = 0;
			//贡献来源
			float gx = 0;
			//区域主管来源
			float zg_cl = 0;
			float zg_zl = 0;
			
			if("吴金丽".equals(tichengbelong)) {
				space_cl = 0.5f;
			} else {
				double task = 10000*10000*10000*10000;
				double sjwcl = curSum912.get(space)==null?0:curSum912.get(space);
				if(xjzs1.equals(space)) {
					task = xjzs1_count;
				} else if(xjybt.equals(space)) {
					task = xjybt_count;
				} else if(xjzs2.equals(space)) {
					task = xjzs2_count;
				} else if(xjaks.equals(space)) {
					task = xjaks_count;
				} else if(xjbz.equals(space)) {
					task = xjbz_count;
				} else if(xjht.equals(space)) {
					task = xjht_count;
				} else if(xjks.equals(space)) {
					task = xjks_count;
				}
				if(sjwcl >= task) {//四品折合量 达成
					System.out.println("完成任务："+space);
					if("B".equals(product)) {
						if("10".equals(pack)) {
							if("自营".equals(mode)) {
								space_zl = 1.5f;
							} else if("小包".equals(mode)) {
								space_zl = 1.0f;
							}
						}
						if("5".equals(pack)) {
							if("自营".equals(mode)) {
								space_zl = 1.0f;
							} else if("小包".equals(mode)) {
								space_zl = 0.7f;
							}
						}
					} else {//其他品种
						if("自营".equals(mode)) {
							space_zl = 1.5f;
						} else if("小包".equals(mode)) {
							space_zl = 1.0f;
						}
					}
				} else {//未达成任务
					if("B".equals(product)) {
						if("10".equals(pack)) {
							if("自营".equals(mode)) {
								space_cl = 1.0f;
							} else if("小包".equals(mode)) {
								space_cl = 0.7f;
							}
						}
						if("5".equals(pack)) {
							if("自营".equals(mode)) {
								space_cl = 0.6f;
							} else if("小包".equals(mode)) {
								space_cl = 0.4f;
							}
						}
					} else {//其他品种
						if("自营".equals(mode)) {
							space_cl = 1.0f;
						} else if("小包".equals(mode)) {
							space_cl = 0.7f;
						}
					}
				}
			}
			
			//晚交流向
			if(wjlx.contains("晚交流向")) {
				space_wj = 0;
				daqu_wj = -0.05f;
			} 
			/***片区来源计算end*/
			
			//初始化参数
			daqu_cl = Float.parseFloat(df.format(daqu_cl));
			daqu_zl = Float.parseFloat(df.format(daqu_zl));
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			daqu_wj = Float.parseFloat(df.format(daqu_wj));
			space_wj = Float.parseFloat(df.format(space_wj));
			gj = Float.parseFloat(df.format(gj));
			gx = Float.parseFloat(df.format(gx));
			zg_cl = Float.parseFloat(df.format(zg_cl));
			zg_zl = Float.parseFloat(df.format(zg_zl));
			
			String daqu_cl_tc = df.format(daqu_cl*scount);
			String daqu_zl_tc = df.format(daqu_zl*scount);
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			String daqu_wj_tc = df.format(daqu_wj*scount);
			String space_wj_tc = df.format(space_wj*scount);
			String gj_tc = df.format(gj*scount);
			String gx_tc = df.format(gx*scount);
			String zg_cl_tc = df.format(zg_cl*scount);
			String zg_zl_tc = df.format(zg_zl*scount);
			
			if("B".equals(product)) {
				daqu_cl_tc = df.format(daqu_cl*countd);
				daqu_zl_tc = df.format(daqu_zl*countd);
				space_cl_tc = df.format(space_cl*countd);
				space_zl_tc = df.format(space_zl*countd);
				daqu_wj_tc = df.format(daqu_wj*countd);
				space_wj_tc = df.format(space_wj*countd);
				gj_tc = df.format(gj*countd);
				gx_tc = df.format(gx*countd);
				zg_cl_tc = df.format(zg_cl*countd);
				zg_zl_tc = df.format(zg_zl*countd);
			} 
			
			params[i] = new Object[] {gx,gx_tc,
					space_cl,space_cl_tc,space_zl,space_zl_tc,
					space_wj,space_wj_tc,gj,gj_tc,
					daqu_cl,daqu_cl_tc,daqu_zl,daqu_zl_tc,
					daqu_wj,daqu_wj_tc,
					zg_cl,zg_cl_tc,zg_zl,zg_zl_tc,id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set gxDanwei=?,gxTc=?, "
				
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=?,"
				+ " spaceKouJian=?,spaceKouJianTc=?,"
				+ " gaoJieDanwei=?,gaoJieTc=?,"
				
				+ " jicengbutie7=?,money7=?,"
				+ " daquZLDanwei=?,daquZLTc=?,"
				+ " daquKouJian=?,daquKouJianTc=?,"
				
				+ " zgDanwei=?,zgTc=?,"
				+ " zgDanwei_zl=?,zgTc_zl=?,"
				
				+ " tcstatus='待Q4' "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}
	/***
	 * 计算新疆，Rx提成
	 * @throws SQLException 
	 */
	public void xjRxTCwcTask() throws SQLException {
		QueryRunner query = new QueryRunner(DataSourceUtils.getDataSource());
		String province="新疆";
		String id="";
		String xsScount="0";
		float scount=0f;
		float countd=0f;
		String mode="";
		String space="";
		String product="";
		String pack="";
		String count="";
		String shengfen="";
		String wjlx="";
		String qudao="";
		String gxTcMan="";
		String zgTcMan="";
		String tichengbelong="";
		
		String sql = " select id id,xsScount xsScount,terminaltype qudao, "
				+ " mode mode,space space,money6 wjlx,gxTcMan gxTcMan,zgTcMan zgTcMan,product,pack,count,tichengbelong "
				+ " from kdb_nss_log_plans "
				+ " where judge ='纯销' "
				+ " and province like '%"+province+"%' "
				+ " and (xieyizhuangtai='Rx') and space in ('新疆巴州','新疆和田') and year = 2018 ";
		List<Object[]> list = query.query(sql, new ArrayListHandler());
		Object[][] params = new Object[list.size()][];
		for(int i=0;i<list.size();i++){
			id = list.get(i)[0]==null?"":list.get(i)[0].toString();
			xsScount = list.get(i)[1]==null?"0":list.get(i)[1].toString();//折量
			qudao = list.get(i)[2]==null?"0":list.get(i)[2].toString();//渠道
			mode = list.get(i)[3]==null?"":list.get(i)[3].toString();//模式
			space = list.get(i)[4]==null?"":list.get(i)[4].toString();//片区
			wjlx = list.get(i)[5]==null?"":list.get(i)[5].toString();//晚交流向
			gxTcMan = list.get(i)[6]==null?"":list.get(i)[6].toString();//贡献提成人
			zgTcMan = list.get(i)[7]==null?"":list.get(i)[7].toString();//区域主管
			product = list.get(i)[8]==null?"":list.get(i)[8].toString();//品种
			pack = list.get(i)[9]==null?"":list.get(i)[9].toString();//包装
			count = list.get(i)[10]==null?"":list.get(i)[10].toString();//数量
			tichengbelong = list.get(i)[11]==null?"":list.get(i)[11].toString();//片区提成人
			try {
				scount = Float.parseFloat(xsScount);
			} catch (NumberFormatException e1) {
				scount=0;
			}
			try {
				countd = Float.parseFloat(count);
			} catch (NumberFormatException e1) {
				countd=0;
			}
			//片区增量,达成
			float space_zl = 0;
			float space_cl = 0;
			
			if("B".equals(product)) {
				if("10".equals(pack)) {
					if("自营".equals(mode)) {
						space_zl = 1.5f;
					} else if("小包".equals(mode)) {
						space_zl = 1.0f;
					}
				}
				if("5".equals(pack)) {
					if("自营".equals(mode)) {
						space_zl = 1.0f;
					} else if("小包".equals(mode)) {
						space_zl = 0.7f;
					}
				}
			} else {//其他品种
				if("自营".equals(mode)) {
					space_zl = 1.5f;
				} else if("小包".equals(mode)) {
					space_zl = 1.0f;
				}
			}
			
			//初始化参数
			space_cl = Float.parseFloat(df.format(space_cl));
			space_zl = Float.parseFloat(df.format(space_zl));
			
			String space_cl_tc = df.format(space_cl*scount);
			String space_zl_tc = df.format(space_zl*scount);
			
			if("B".equals(product)) {
				space_cl_tc = df.format(space_cl*countd);
				space_zl_tc = df.format(space_zl*countd);
			} 
			
			params[i] = new Object[] {
					space_cl,space_cl_tc,
					space_zl,space_zl_tc,
					id};
		}
		String update = " update kdb_nss_log_plans "
				+ " set "
				+ " danwitichen=?,shijiticheng=?,"
				+ " spaceZLDanwei=?,spaceZLTc=? "
				+ " where 1=1 and id=?";
		query.batch(update, params);
	}

	
	public static void main(String[] args) {
		new PlanTichenController().y2018tc4();
	}
}
